package org.jeecg.modules.demo.pcl.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @Description: mes-tpm-评分均值
 * @Author: jeecg-boot
 * @Date:   2025-02-18
 * @Version: V1.0
 */
@Service
@DS("mes-mes-datasource")
public class RestfulMesBoardServiceImpl {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Result<List<Workcell>> getworkcell() throws SQLException {
        String sql = "SELECT WORKCELL_ID, WORKCELL_NAME FROM ksm_model.mt_mod_workcell WHERE workcell_type = 'STATION'";

        List<Workcell> workcells = jdbcTemplate.query(sql, new RowMapper<Workcell>() {
            @Override
            public Workcell mapRow(ResultSet rs, int rowNum) throws SQLException {
                Workcell workcell = new Workcell();
                workcell.setWorkcellId(rs.getString("WORKCELL_ID"));
                workcell.setWorkcellName(rs.getString("WORKCELL_NAME"));
                return workcell;
            }
        });

        // 创建 Result 对象并设置数据
        Result<List<Workcell>> result = new Result<>();
        result.setResult(workcells);
        result.setMessage("Success");
        result.setCode(200);

        return result;
    }

    public static class Workcell {
        private String workcellId;
        private String workcellName;

        // Getters and Setters
        public String getWorkcellId() {
            return workcellId;
        }

        public void setWorkcellId(String workcellId) {
            this.workcellId = workcellId;
        }

        public String getWorkcellName() {
            return workcellName;
        }

        public void setWorkcellName(String workcellName) {
            this.workcellName = workcellName;
        }

        @Override
        public String toString() {
            return "Workcell{" +
                    "workcellId='" + workcellId + '\'' +
                    ", workcellName='" + workcellName + '\'' +
                    '}';
        }
    }
}
